﻿/********************************************************************************
*Description: 相机操作工作类
*FunParameter:
*FunReturnValue:
*Author:Gaojia
*Date:2022/03/23
*ChangeDate:
*Modifier:
*ModifyReason:
*Version:V1.0.0
********************************************************************************/
#ifndef CCamerSdkOper_H
#define CCamerSdkOper_H
#include <QObject>
#include "HCNetSDK.h"
#include "CDevDataBase.h"
//#include <gdiplus.h>
//#pragma comment(lib, "Gdiplus.lib")
//using namespace Gdiplus;
//
//#include <mmiscapi.h>


class CCamerSdkOper : public QObject
{
	Q_OBJECT

public:
	CCamerSdkOper(CDevDataCam *pDevDataCam);
	CCamerSdkOper();
	~CCamerSdkOper();
	void getDevCfg();                                      //获取设备的通道资源
	void getDecoderCfg();                                  //获取云台解码器信息
	bool initAndLogin(QString &sReInfo);                                      //初始化和连接
	bool initCamer(QString &sReInfo);                                         //初始化相机
	bool loginCamer(QString &sReInfo);                                        //用户注册设备
	bool login(QString &sReInfo);											  //外部登录命令
	bool realPlay(int nDevId, QString &sReInfo);                              //启动预览 无句柄
	virtual bool realPlay(int nDevId, HWND hHand, QString &sReInfo);          //启动预览 有句柄 
	virtual bool realPlay(int nDevId, HWND hHand,QWidget *pWidget, QString &sReInfo); //启动预览 有句柄 
	bool stopRealPlay(int nDevId, QString &sReInfo);                          //停止预览 无句柄
	virtual bool stopRealPlay(HWND hHand, QString &sReInfo);                  //停止预览 有句柄 
	bool ptzPresetOther(int nPresetIndex, int nCmd, QString &sReInfo);        //设置预置点和转到预置点
	bool capture(int nDevId, QString &sPath, QString &sReInfo);               //拍照  
	bool ptzControlOther(int nCmd, int nSpeed, bool bRun, QString &sReInfo);  //控制云台
	bool recordVideo(QString &sPath, int nDevId, QString &sReInfo);           //录像无句柄 
	bool recordVideo(QString &sPath, HWND hHand, QString &sReInfo);           //录像 
	bool stopRecordVideo(int nDevId, QString &sReInfo);                       //停止录像无句柄 
	bool stopRecordVideo(HWND hHand, QString &sReInfo);                       //停止录像 
	bool startVoiceTalk(int nDevId, QString &sReInfo);                        //启动对讲
	bool stopVoiceTalk(int nDevId, QString &sReInfo);                         //停止对讲
	bool startVoiceForward(int nDevId, QString &sReinfo);					  //开始语音转发
	bool endVoiceForward(int nDevId, QString &sReinfo);					      //关闭语音转发
	bool broadcastAudio(int nDevId, QString &sReInfo);													 //播报音频文件
	void drawTempInfo(LONG lRealHandle, HDC hDc, DWORD dwUser);              //画温度信息 addwxy
	void drawRollerNum(LONG lRealHandle, HDC hDc, DWORD dwUser);             //画托辊号
	virtual void setRollerNum(int nNum, int nBologn,QString sRollerDesc);         //设置托辊号
	virtual void setCorrectData(double dLeftRectifyValue, double dRightRectifyValue, int nRectifySetValue, int nRectifySetValueTwo, QPointF BeltEdgePf1, QPointF BeltEdgePf2, QPointF BeltEdgePf3, QPointF BeltEdgePf4,
		int nIsHaveBeltState, bool bBeltState,int nDrawType);
	void drawCorrect(LONG lRealHandle, HDC hDc, DWORD dwUser);             //画跑偏数据
	/*azq++ 202406171541 增加专家模式和红外检测框选*/
	bool setCameraMode(LONG lUserID, ECameraMode enModeType, QString& sErrMsg);	//设置相机模式
	bool setPresetArea(LONG lUserID, SPersetAreaParam sPersetData, SPersetAreaRect detectRect, QString& sErrMsg);  //预置点框选区域配置(框选)

private:
	bool captureIr(QString &sPath, QString &sReInfo);                        //红外拍照
	bool captureImg(QString &sPath, QString &sReInfo);                       //图像拍照
	QString getErrMsg();
	bool setSTDConfig(LONG lUserID);//设置测温配置 addwxy


private:
	QMap<int, QString> m_mapCmdName;//命令名称
	int m_nDrawType;//0:机器人画托辊  1:跑偏画线及左下角显示纠偏值
	//机器人画托辊相关
	int m_nRollerNum;  //托辊号
	QString m_sRollerDesc;
	int m_nBelogn;    //AB侧托辊

	//跑偏画线和左下角文字相关
	QPointF m_BeltEdgePf1;//皮带边缘点1 左上
	QPointF m_BeltEdgePf2;//皮带边缘点2 右上
	QPointF m_BeltEdgePf3;//皮带边缘点3 右下
	QPointF m_BeltEdgePf4;//皮带边缘点4 左下
	double m_dLeftRectifyValue;//左偏值
	double m_dRightRectifyValue;//右偏值
	int m_nRectifySetValue;//一级跑偏判定值
	int m_nRectifySetValueTwo;//二级跑偏判定值
	int m_nIsHaveBeltState;//是否有皮带运行状态
	int m_bBeltState;//皮带运行状态

public:
	CDevDataCam *m_pDevDataCam = nullptr;

public:
	double m_dTempMax;       //最高温度
	double m_dTempMin;       //最低温度
	double m_dTempAverage;   //平均温度
	QPointF m_cTempMaxPoint;  //最高温度点
	QPointF m_cTempMinPoint;  //最低温度点
	double m_dValue;//声音分贝值


	//HMMIO m_hmmio;//音频系统接口句柄
	//声音采样设置参数
	qint32 m_nSampleInterval;//采样抽帧间隔
	qint32 m_nAvgInterval;//求分贝平均数间隔，过滤掉突变数据
	qreal m_dDbUprate;//采样值增幅(若采用原采样值计算的分贝数可能与仪器采集不对应，可按比例增大采样值以对应实际数据)
	QVector<qint32> m_vecDb;//近几帧数据(抽帧后的数据，用于计算方差)
	qint32 m_nDbDeviationNum;			//求方差的数据组数量

	qint32 m_nCount;					//采样间隔计数

	qint32 m_nDbNum;					//分贝值
	qint32 m_nDbNumOld;					//上一次采集的分贝值
	qint32 m_nDbNumDiffer;				//分贝值与上一次的差值
	qreal m_dDbDeviation;				//分贝值方差
	QVector<qint32> m_vecDbOrigin;		//原始数据近几帧分贝数，数组大小由m_nAvgInterval决定

signals:
	//传出pcm原始数据
	void sigAnalyzePCMData(QByteArray szPCMData);
	//传出分贝、差值与方差
	//void sigGetDbNum(qint32 nDbNum, qint32 nDbDiffer, qreal nDbDeviation);

public slots:
	//分析回调函数给出的pcm原始数据
	void slotAnalyzePCMData(QByteArray szPCMData);

};

#endif